﻿using System;
using System.Collections.Generic;
using System.IO;
using Windows.UI.Xaml.Media.Imaging;
using System.Linq;
using System.Windows.Input;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Input;
using Windows.UI.Core;
using System.Threading;
using System.Collections.Concurrent;
namespace RoboRun
{
    class Layout
    {
        
        public void loadPlayButton(Image image, float width, float height, float offset)
        {

            image.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/playbutton.png", UriKind.Absolute
                  ));
            image.Height = 80 * height/ 1080;
            image.Width = 80 * width / 1920;
            image.Margin = new Thickness(665 * width / 1920, offset/2 + 490 * height / 1080, 0, 0);
        }

        public void loadLabels(Image playLabel, Image undoLabel, float width, float height, float offset)
        {
            playLabel.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/playlabel.png", UriKind.Absolute
                  ));
            playLabel.Height = 47 * height/ 1080;
            playLabel.Width = 63 * width / 1920;
            playLabel.Margin = new Thickness(673 * width / 1920, offset/2 + 567 * height / 1080, 0, 0);

            undoLabel.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/undolabel.png", UriKind.Absolute
                  ));
            undoLabel.Height = 27 * height/ 1080;
            undoLabel.Width = 77 * width / 1920;
            undoLabel.Margin = new Thickness(540 * width / 1920, offset/2 + 570 * height / 1080, 0, 0);
        }
        

        public void loadUndoButton(Image image)
        {
            image.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/undobutton.png", UriKind.Absolute
                  ));
            image.Height = 80 * GameplayScreen.height / 1080;
            image.Width = 80 * GameplayScreen.width / 1920;
            image.Margin = new Thickness(540 * GameplayScreen.width / 1920, GameplayScreen.offset/2 + 490 * GameplayScreen.height / 1080, 0, 0);
        }

        public void loadRobotSprite(Image image, float width, float height, float offset,String GridType,String RobotStartingDirection,String RobotStartingPosition)
        {
            if (GridType.Equals("3x3"))
            {
                image.Width = 300 * width / 1920;
                image.Height = 300 * height / 1080;
                loadingRobotSprite.loadRobotInCorrectDirection3x3(RobotStartingDirection, image);
                drawInPosition.drawInPosition3x3(image, RobotStartingPosition, offset);
            }
            else if (GridType.Equals("4x4"))
            {
                image.Width = 290 * width / 1920;
                image.Height = 271 * height / 1080;
                loadingRobotSprite.loadRobotInCorrectDirection4x4(RobotStartingDirection, image);
                drawInPosition.drawInPosition4x4(image, RobotStartingPosition, offset);
            }

        }

        public void loadGoal(Image image, String GridType)
        {
            if (GridType.Equals("3x3"))
            {
                image.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/3X3Grid/goal.png", UriKind.Absolute
                  ));
                image.Width = 300 * GameplayScreen.width / 1920;
                image.Height = 300 * GameplayScreen.height / 1080;
                drawInPosition.drawInPosition3x3(image, GameplayScreen.GoalPosition, GameplayScreen.offset);
            }
            else if (GridType.Equals("4x4"))
            {
                image.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/4X4Grid/goal.png", UriKind.Absolute
                  ));
                image.Width = 290 * GameplayScreen.width / 1920;
                image.Height = 271 * GameplayScreen.height / 1080;
                drawInPosition.drawInPosition4x4(image, GameplayScreen.GoalPosition, GameplayScreen.offset);
            }
        }

        

        public void loadCommandsTitle(Image CommandsTitle, float width, float height, float offset)
        {
            CommandsTitle.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/commandstext.png", UriKind.Absolute
                   ));
            CommandsTitle.Width = 356 * width / 1920;
            CommandsTitle.Height = 58 * height / 1080;
            CommandsTitle.Margin = new Thickness(183 * width / 1920, offset + 18 * height / 1080, 0, 0);
        }

        public void loadControlsTitle(Image ControlsTitle, float width, float height, float offset)
        {
            ControlsTitle.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/controlstext.png", UriKind.Absolute
                   ));
            ControlsTitle.Width = 272 * width / 1920;
            ControlsTitle.Height = 58 * height / 1080;
            ControlsTitle.Margin = new Thickness(237 * width / 1920, 670 * height / 1080 - (offset / 4), 0, 0);
        }

        public void loadGoStraightButton(Image GoStraightButtonImage, Button GoStraightButton, float width, float height, float offset)
        {
            GoStraightButtonImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/ControlsButtons/gostraightbutton.png", UriKind.Absolute
                   ));
            GoStraightButtonImage.Width = 293 * width / 1920;
            GoStraightButtonImage.Height = 66 * height / 1080;
            GoStraightButtonImage.Margin = new Thickness(48 * width / 1920, 778 * height / 1080 - (offset / 4), 0, 0);
            GoStraightButton.Width = 293 * width / 1920;
            GoStraightButton.Height = 66 * height / 1080;
            GoStraightButton.Margin = new Thickness(48 * width / 1920, 778 * height / 1080 - (offset / 4), 0, 0);
        }

        public void loadIfButton(Image IfButtonImage, Button IfButton)
        {
            IfButtonImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/ControlsButtons/ifbutton.png", UriKind.Absolute
                   ));
            IfButtonImage.Width = 293 * GameplayScreen.width / 1920;
            IfButtonImage.Height = 66 * GameplayScreen.height / 1080;
            IfButtonImage.Margin = new Thickness(415 * GameplayScreen.width / 1920, 778 * GameplayScreen.height / 1080 - (GameplayScreen.offset / 4), 0, 0);
            IfButton.Width = 293 * GameplayScreen.width / 1920;
            IfButton.Height = 66 * GameplayScreen.height / 1080;
            IfButton.Margin = new Thickness(415 * GameplayScreen.width / 1920, 778 * GameplayScreen.height / 1080 - (GameplayScreen.offset / 4), 0, 0);
        }

        public void loadForButton(Image ForButtonImage, Button ForButton)
        {
            ForButtonImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/ControlsButtons/forbutton.png", UriKind.Absolute
                   ));
            ForButtonImage.Width = 293 * GameplayScreen.width / 1920;
            ForButtonImage.Height = 66 * GameplayScreen.height / 1080;
            ForButtonImage.Margin = new Thickness(415 * GameplayScreen.width / 1920, 868 * GameplayScreen.height / 1080 - (GameplayScreen.offset / 2), 0, 0);
            ForButton.Width = 293 * GameplayScreen.width / 1920;
            ForButton.Height = 66 * GameplayScreen.height / 1080;
            ForButton.Margin = new Thickness(415 * GameplayScreen.width / 1920, 868 * GameplayScreen.height / 1080 - (GameplayScreen.offset / 2), 0, 0);
        }

        public void loadTurnLeftbutton(Image TurnLeftButtonImage, Button TurnLeftButton, float width, float height, float offset)
        {
            TurnLeftButtonImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/ControlsButtons/turnleftbutton.png", UriKind.Absolute
                   ));
            TurnLeftButtonImage.Width = 293 * width / 1920;
            TurnLeftButtonImage.Height = 66 * height / 1080;
            TurnLeftButtonImage.Margin = new Thickness(48 * width / 1920, 868 * height / 1080 - (offset / 2), 0, 0);
            TurnLeftButton.Width = 293 * width / 1920;
            TurnLeftButton.Height = 66 * height / 1080;
            TurnLeftButton.Margin = new Thickness(48 * width / 1920, 868 * height / 1080 - (offset / 2), 0, 0);
        }

        public void loadTurnRightButton(Image TurnRightButtonImage, Button TurnRightButton, float width, float height, float offset)
        {
            TurnRightButtonImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/ControlsButtons/turnrightbutton.png", UriKind.Absolute
                   ));
            TurnRightButtonImage.Width = 293 * width / 1920;
            TurnRightButtonImage.Height = 66 * height / 1080;
            TurnRightButtonImage.Margin = new Thickness(48 * width / 1920, 958 * height / 1080 - (offset / 2 + offset/4), 0, 0);
            TurnRightButton.Width = 293 * width / 1920;
            TurnRightButton.Height = 66 * height / 1080;
            TurnRightButton.Margin = new Thickness(48 * width / 1920, 958 * height / 1080 - (offset /2 + offset/4), 0, 0);
        }

        public void loadWhileButton(Image WhileButtonImage, Button WhileButton)
        {
            WhileButtonImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/ControlsButtons/whilebutton.png", UriKind.Absolute
                   ));
            WhileButtonImage.Width = 293 * GameplayScreen.width / 1920;
            WhileButtonImage.Height = 66 * GameplayScreen.height / 1080;
            WhileButtonImage.Margin = new Thickness(415 * GameplayScreen.width / 1920, 958 * GameplayScreen.height / 1080 - (GameplayScreen.offset / 2 + GameplayScreen.offset / 4), 0, 0);
            WhileButton.Width = 293 * GameplayScreen.width / 1920;
            WhileButton.Height = 66 * GameplayScreen.height / 1080;
            WhileButton.Margin = new Thickness(415 * GameplayScreen.width / 1920, 958 * GameplayScreen.height / 1080 - (GameplayScreen.offset / 2 + GameplayScreen.offset / 4), 0, 0);
        }

        public void setUpCommandQueueTextBox(ScrollViewer commandQueueScrollViewer,TextBlock commandQueueTextBox, float height, float width, float offset)
        {
            commandQueueScrollViewer.Width = 748 * width / 1920;
            commandQueueScrollViewer.Height = 600 * height / 1920;
            commandQueueScrollViewer.Margin = new Thickness(20 * width / 1920, offset/2 + 130 * height / 1080, 0, 0);
            commandQueueTextBox.FontSize = height / 30;
        }

        public static void loadLayout(Image CommandsBG, Image GridBG, Image ControlsBG, Image Grid, float height, float width, float offset)
        {
            CommandsBG.Width = 768 * width / 1920;
            CommandsBG.Height = 648 * height / 1080;
            CommandsBG.Margin = new Thickness(0, offset, 0, 0);
            ControlsBG.Width = 768 * width / 1920;
            ControlsBG.Height = 431 * height / 1080;
            ControlsBG.Margin = new Thickness(0, 0, 0, offset);
            GridBG.Height = 1080 * height / 1080;
            GridBG.Margin = new Thickness(768 * width / 1920, offset, 0, 0);
            Grid.Width = 1151 * width / 1920;
            Grid.Height = 1080 * height / 1080;
            GridBG.Margin = new Thickness(768 * width / 1920, offset, 0, 0);
            Grid.Margin = new Thickness(768 * width / 1920, offset, 0, 0);
            //Set source depending on what kind of grid it is. 2x2, 3x3, 4x4, 5x5 or 6x6
            switch (GameplayScreen.GridType)
            {
                case ("3x3"):
                    Grid.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/3X3Grid/3x3grid.png", UriKind.Absolute
                    ));
                    break;
                case ("4x4"):
                    Grid.Source = new BitmapImage(new Uri("ms-appx:///Assets/GameplayScreen/4X4Grid/4x4grid.png", UriKind.Absolute
                    ));
                    break;
            }
            }
        }
    }

